package de.baumann.browser.activitys.explore

import android.content.Context
import android.content.Intent
import android.support.v4.view.ViewPager
import android.view.Menu
import android.view.MenuItem
import de.baumann.browser.R
import de.baumann.browser.adapter.PagerAdapter
import de.baumann.browser.base.BaseUnModelActivity
import de.baumann.browser.fragments.explore.OdinDestroyRecordFragment
import de.baumann.browser.fragments.explore.OtherDestroyRecordFragment
import kotlinx.android.synthetic.main.activity_destory_record.*
import kotlinx.android.synthetic.main.include_tool_bar.*

class DestroyRecordActivity : BaseUnModelActivity() {


    companion object {
        fun startDestroyRecordActivity(context: Context) {
            context.startActivity(Intent(context, DestroyRecordActivity::class.java))
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_destory_record
    }

    override fun getTitleText(): String {
        return "销毁算力记录"
    }


    override fun initView() {
        initToolbar(commToolBar, commTitle)
        val fragments = arrayListOf(
                OdinDestroyRecordFragment.instance,
                OtherDestroyRecordFragment.instance
        )
        val adapter = PagerAdapter(supportFragmentManager, fragments, null)
        viewPager.adapter = adapter
        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {
                when (position) {
                    0 -> rbOdinDestroy.isChecked = true
                    1 -> rbOtherDestroy.isChecked = true
                }
            }
        })

        rgDestroy.setOnCheckedChangeListener { _, p1 ->
            when (p1) {
                R.id.rbOdinDestroy -> viewPager.currentItem = 0
                R.id.rbOtherDestroy -> viewPager.currentItem = 1
            }
        }
    }

    override fun onResume() {
        super.onResume()
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_team, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        MineTeamActivity.startMineTeamActivity(this)
        return super.onOptionsItemSelected(item)
    }

    override fun initData() {

    }
}